const { User } = require('../../model/user');
module.exports = async(req, res, next) => {
    // 接收修改的参数
    const { username, email, role, statue, password } = req.body;
    // 接收get参数id
    const id = req.query.id;
    // 查找用户
    const user = await User.findOne({ _id: id });
    // 密码对比
    if (user.password == password) {
        // res.send('ok');
        // 将用户信息更新到数据库中
        await User.updateOne({ _id: id }, {
            username: username,
            email: email,
            role: role,
            statue: statue
        });
        res.redirect('/admin/user');
    } else {
        let obj = { path: '/admin/user-edit', message: '密码错误', id: id };
        next(JSON.stringify(obj));
    }
}